<template>
    <div class="app-container calendar-list-container">
      <el-button
        icon="el-icon-circle-plus-outline"
        type="button"
        class="el-button el-button--primary"
        @click="toAddprocess"
        style="margin-bottom: 20px"
        v-if="userInfo.roleId != '35' && userInfo.roleId != '36' && userInfo.roleId != '30' && userInfo.roleId != '37' && userInfo.roleId != '16'"
        >
        录入产品工艺路线</el-button>
      <div class="filter-container" v-if="userInfo.roleId != '35' && userInfo.roleId != '36' && userInfo.roleId != '30' && userInfo.roleId != '37' && userInfo.roleId != '16'">
        <el-input
              @keyup.enter.native="addProcessBtn"
              clearable
              v-model="technologyNo"
              style="width: 160px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="请输入产品编号"
        ></el-input>
        <el-button class="filter-item" :loading="loadingBtn" type="primary" v-waves icon="el-icon-plus" @click="addProcessBtn">添加</el-button>
      </div>



      <!-- 查询工艺路线列表 -->
      <div class="filter-container">
        <el-input
              @keyup.enter.native="getData"
              clearable
              v-model="listQuery.technologyNo"
              style="width: 160px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="请输入产品编号"
        ></el-input>
        <el-input
              @keyup.enter.native="getData"
              clearable
              v-model="listQuery.technologyEnd"
              style="width: 160px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="末端产品编号"
        ></el-input>
        <el-input
              @keyup.enter.native="getData"
              clearable
              v-model="listQuery.processNo"
              style="width: 150px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="请输入工序编号"
        ></el-input>
        <el-input
              @keyup.enter.native="getData"
              clearable
              v-model="listQuery.processName"
              style="width: 150px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="请输入工序名称"
        ></el-input>
        <!-- 2022/3/28 15:04 关键字搜索，输入工作中心搜索改为选择工作中心 -->
        <!-- <el-select
              clearable
              v-model="listQuery.workCenter"
              placeholder="请选择工作中心"
              @focus="getCenterList"
              style="width: 150px;margin-right:15px;margin-top:7px"
              class="filter-item">
          <el-option :value="item" :label="item" v-for="(item,index) in this.centerList.data" :key="index"/>
        </el-select> -->

        <el-input
              @keyup.enter.native="getData"
              clearable
              v-model="listQuery.workCenter"
              style="width: 150px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="请输入工作中心"
        ></el-input>
        <el-select
              clearable
              @keyup.enter.native="getData"
              v-model="listQuery.department"
              @focus="getDepartInfo"
              style="width: 150px;margin-right:15px;margin-top:7px"
              class="filter-item"
              placeholder="请输入员工部门" >
          <el-option :value="item" :label="item" v-for="(item,index) in this.departList" :key="index"/>
        </el-select>
        <!-- 对员工的职级进行查询 -->
        <el-cascader
              v-model="listQuery.jobClass"
              separator="-"
              :options="options"
              clearable
              placeholder="请输入职级"
              @keyup.enter.native="getData"
              style="width: 150px;margin-right:15px;margin-top:7px">
        </el-cascader>
        <el-select
            clearable
            @keyup.enter.native="getData"
            v-model="listQuery.isDelete"
            placeholder="审核是否通过"
            class="filter-item"
            style="width: 150px;margin-right:15px;margin-top:7px">
            <el-option
                v-for="(item,index) in optionsYS"
                :key="index"
                :label="item"
                :value="item">
            </el-option>
        </el-select>
        <el-button style="margin-top: 7px" class="filter-item" :loading="searchLoadingBtn" type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
      </div>

      <!-- 工艺路线列表 -->
      <el-table :data="dealList" :height="height" v-loading="listLoading" element-loading-text="拼命加载中"  stripe border fit highlight-current-ro style="width: 100%">
          <el-table-column  label="序号" type="index" align="center"/>
          <el-table-column  label="工序ID" prop="processId" align="center"/>
          <el-table-column  label="加工顺序" prop="processOrder" align="center"/>
          <el-table-column  label="产品编号" prop="technologyNo" align="center" width="100"/>
          <el-table-column  label="品名"  prop="technologyName" align="center" width="250"/>
          <el-table-column  label="规格"  prop="specification" align="center"/>
          <el-table-column  label="栈板数量" prop="palletCodeCount" align="center"/>
          <el-table-column  label="器件数量" prop="deviceCodeCount" align="center"/>
          <el-table-column  label="附件数量" prop="accessoryCodeCount" align="center"/>
          <el-table-column  label="工序编号" prop="processNo" align="center"/>
          <el-table-column  label="工序名称" prop="processName" align="center"/>
          <el-table-column  label="工序小类" prop="processNameGz" align="center"/>
          <el-table-column  label="刀数" prop="knife" align="center">
            <template slot-scope="scope">
                <div class="fx " :class="{wrong:scope.row.knife==0 && scope.row.department=='数控车间'}">
                  {{
                    scope.row.knife
                  }}
                </div>
            </template>
          </el-table-column>
          <el-table-column  label="长" prop="length" align="center"/>
          <el-table-column  label="宽" prop="wide" align="center"/>
          <el-table-column  label="重" prop="weight" align="center"/>
          <el-table-column  label="加工次数" prop="processCount" align="center"/>
          <el-table-column  label="铆钉数量" prop="rivetCount" align="center"/>
          <el-table-column  label="板材" prop="texture" align="center"/>
          <el-table-column  label="板厚" prop="thickness" align="center"/>
          <el-table-column  label="连焊长度" prop="weldLength" align="center"/>
          <el-table-column  label="焊点数量" prop="weldingSpot" align="center"/>
          <el-table-column  label="碰焊点数" prop="buttJoint" align="center"/>
          <el-table-column  label="外购件数量" prop="assembleConfig3" align="center" width="100"/>
          <el-table-column  label="螺钉数量" prop="assembleConfig2" align="center"/>
          <el-table-column  label="打胶长度" prop="assembleConfig4" align="center"/>
          <el-table-column  label="不锈钢螺钉数量" prop="assembleConfig5" align="center"/>
          <el-table-column  label="功率螺钉数量" prop="assembleConfig6" align="center"/>
          <el-table-column  label="零件数量" prop="assembleConfig1" align="center"/>
          <el-table-column  label="保护面积" prop="ptProtectionArea" align="center"/>
          <el-table-column  label="保护个数" prop="protectionNumber" align="center"/>
          <el-table-column  label="喷涂面积" prop="partArea" align="center"/>
          <el-table-column  label="工作中心" prop="workCenter" align="center"/>
          <el-table-column  label="固定人时(M)" prop="manTime" align="center"/>
          <el-table-column  label="变动人时(M)" prop="manTimeFloat1" align="center"/>
          <el-table-column  label="部门" prop="department" align="center"/>
          <el-table-column  label="职级" prop="jobClass" align="center"/>
          <!-- 0删除（工艺经理未审核通过），1未删除（工艺经理已审核通过） -->
          <el-table-column  label="审核是否通过" align="center" width="160" v-if="userInfo.roleId != 30 && userInfo.roleId != 37 && userInfo.roleId != 16">
            <template slot-scope="scope" >
              <el-switch
              v-model="scope.row.isDelete"
              active-text="是"
              inactive-text="否"
              @change="upDateProcess(scope.$index,scope.row)">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column  label="工艺说明" prop="remark" align="center" width="100"/>
          <!-- 对工艺进行修改与删除 -->
          <el-table-column  label="操作" fixed="right" align="center" width="160" v-if="userInfo.roleId != 30 && userInfo.roleId != 37 && userInfo.roleId != 16">
            <template slot-scope="scope" >
              <el-button size="mini" type="primary" @click="handleEdit(scope.row)">设置</el-button>
              <el-button size="mini" type="danger" @click="handleDelete(scope.$index,scope.row)">删除</el-button>
            </template>
          </el-table-column>
      </el-table>

      <div slot="tip" class="el-upload__tip">提示：M指的是分钟,S指的是秒</div>

    <!-- 修改工艺信息弹出表单 -->
    <el-dialog title="工艺信息修改" :visible.sync="dialogFormVisible" width="700px">
    <el-form :model="modifyform" :rules="rules" ref="modifyform">
      <el-form-item label="工序ID" :label-width="formLabelWidth">
        <el-input v-model="modifyform.processId" style="width:400px" disabled/>
      </el-form-item>
      <el-form-item label="加工顺序" :label-width="formLabelWidth">
        <el-input clearable v-model="modifyform.processOrder" style="width:400px"/>
      </el-form-item>
      <el-form-item label="工序名称" :label-width="formLabelWidth">
        <el-select filterable clearable v-model="modifyform.processName" @focus="getprocessNo" @change="setProcess" style="width:400px">
            <el-option :value="item.processName" :label="item.processName" v-for="(item,index) in this.processList" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="工序编号:" :label-width="formLabelWidth">
          <el-select filterable clearable v-model="modifyform.processNo" @focus="getprocessNo" @change="setProcessNo" style="width:400px">
            <el-option :value="item.processNo" :label="item.processNo" v-for="(item,index) in this.processList" :key="index"/>
          </el-select>
      </el-form-item>
      <!-- <el-form-item label="工序编号" :label-width="formLabelWidth">
        <el-input clearable v-model="modifyform.processNo" style="width:400px"/>
      </el-form-item> -->
      <el-form-item label="刀数" :label-width="formLabelWidth" v-if="showOrhide('刀数')">
        <el-input v-model="modifyform.knife" style="width:400px"/>
      </el-form-item>
      <el-form-item label="固定人时(S)" :label-width="formLabelWidth">
        <el-input clearable v-model.number="modifyform.manTime" style="width:400px"/>
      </el-form-item>
      <el-form-item label="工序小类" :label-width="formLabelWidth">
        <el-select clearable v-model="modifyform.processNameGz" v-if="modifyform.processName.indexOf('钳铆') == 0" style="width:400px">
            <el-option :value="item" :label="item" v-for="(item,index) in this.processNameGzList" :key="index"/>
          </el-select>
          <el-select clearable v-model="modifyform.processNameGz" v-else-if="modifyform.workCenter == 'EMS总装车间'" style="width:400px">
            <el-option :value="item" :label="item" v-for="(item,index) in this.processActionMin" :key="index"/>
          </el-select>
          <el-input
            clearable
            v-model="modifyform.processNameGz"
            v-else
             style="width:400px"
             ></el-input>
      </el-form-item>
      <!-- 喷涂新增 -->
      <el-form-item label="保护面积" :label-width="formLabelWidth" v-if="showOrhide('保护面积')">
        <el-input clearable v-model="modifyform.ptProtectionArea" style="width:400px"/>
      </el-form-item>
      <el-form-item label="喷涂面积" :label-width="formLabelWidth" v-if="showOrhide('喷涂面积')">
        <el-input clearable v-model="modifyform.partArea" style="width:400px"/>
      </el-form-item>
      <el-form-item label="保护个数" :label-width="formLabelWidth" v-if="showOrhide('保护个数')">
        <el-input clearable v-model="modifyform.protectionNumber" style="width:400px"/>
      </el-form-item>
      <el-form-item label="加工次数" :label-width="formLabelWidth" v-if="showOrhide('加工次数')">
        <el-input clearable v-model="modifyform.processCount" style="width:400px"/>
      </el-form-item>
      <el-form-item label="铆钉数量" :label-width="formLabelWidth" v-if="showOrhide('铆钉数量')">
        <el-input clearable v-model="modifyform.rivetCount" style="width:400px"/>
      </el-form-item>
      <!-- <el-form-item label="板材" :label-width="formLabelWidth">
        <el-input clearable v-model="modifyform.texture" style="width:400px"/>
      </el-form-item> -->
      <el-form-item label="板材" :label-width="formLabelWidth" v-if="showOrhide('板材')">
        <el-select clearable v-model="modifyform.texture" @focus="getTextureList" style="width:400px">
          <el-option :value="item.texture" :label="item.texture" v-for="(item,index) in this.textureList" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="连焊长度" :label-width="formLabelWidth" v-if="showOrhide('连焊长度')">
        <el-input clearable v-model="modifyform.weldLength" style="width:400px"/>
      </el-form-item>
      <el-form-item label="焊点数量" :label-width="formLabelWidth" v-if="showOrhide('焊点数量')">
        <el-input clearable v-model="modifyform.weldingSpot" style="width:400px"/>
      </el-form-item>
      <el-form-item label="碰焊点数" :label-width="formLabelWidth" v-if="showOrhide('碰焊点数')">
        <el-input clearable v-model="modifyform.buttJoint" style="width:400px"/>
      </el-form-item>
      
    <el-form-item :label-width="formLabelWidth" label="零件数量:" prop="assembleConfig1" v-if="showOrhide('零件数量')">
      <el-input
      clearable
      v-model.number="modifyform.assembleConfig1"
      style="width:400px"
      ></el-input>
    </el-form-item>
    <el-form-item :label-width="formLabelWidth" label="螺钉数量:" prop="assembleConfig2" v-if="showOrhide('螺钉数量')">
      <el-input
      clearable
      v-model.number="modifyform.assembleConfig2"
          style="width:400px"
          ></el-input>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="外购件数量:" prop="assembleConfig3" v-if="showOrhide('外购件数量')">
          <el-input
          clearable
          v-model.number="modifyform.assembleConfig3"
          style="width:400px"
          ></el-input>
      </el-form-item>
      <el-form-item :label-width="formLabelWidth" label="打胶长度:" prop="assembleConfig4" v-if="showOrhide('打胶长度')">
        <el-input
        clearable
        v-model.number="modifyform.assembleConfig4"
        style="width:400px"
        ></el-input>
      </el-form-item>
      <el-form-item :label-width="formLabelWidth" label="不锈钢螺钉数量:" prop="assembleConfig5" v-if="showOrhide('不锈钢螺钉数量')">
        <el-input
        clearable
        v-model.number="modifyform.assembleConfig5"
        style="width:400px"
        ></el-input>
      </el-form-item>
      <el-form-item :label-width="formLabelWidth" label="功率螺钉数量:" prop="assembleConfig6" v-if="showOrhide('功率螺钉数量')">
        <el-input
        clearable
          v-model.number="modifyform.assembleConfig6"
          style="width:400px"
          ></el-input>
        </el-form-item>
        <div v-if="modifyform.technologyNo.startsWith('HW')">
          <el-form-item label="工序动作" :label-width="formLabelWidth">
            <!-- <el-input clearable v-model.number="modifyform.manTime" style="width:400px"/>processAction -->
            <el-select filterable clearable v-model="modifyform.actionAbbreviation" @change="setProcessActionNo" style="width:400px">
              <el-option :value="item.name" :label="item.name" v-for="(item,index) in this.processAction" :key="index"/>
            </el-select>
        </el-form-item>
        <el-form-item label="系数类型" :label-width="formLabelWidth">
          <el-select filterable clearable v-model="modifyform.emsCoefficientType" @focus="coefficientFocus" style="width:400px">
            <el-option :value="item" :label="item" v-for="(item,index) in this.coefficientList" :key="index"/>
          </el-select>
        </el-form-item>
        <el-collapse>
          <el-collapse-item title="物料编码维护" style="margin-left: 30px;">
            <div v-for="(item, index) in typeList" :key="index" style="margin-bottom: -22px;background-color: #dbf1e1;">
              <el-divider></el-divider>
              <div style="display: flex;justify-content: space-between;">
                <div style="display: flex;">
                  <el-form-item label-width="80px" label="物料编码">
                    <!-- <el-input clearable v-model="item.materialCode" style="width:200px"></el-input> -->
                    <el-select disabled filterable clearable style="width:220px" v-model.trim="item.elementTechnologyNo"  @change="logyNoChange($event,index)" placeholder="请选择物料编码">
                      <el-option :value="item1.CB005" :label="item1.CB005" v-for="(item1,index1) in materialCodeList" :key="index1"/>
                    </el-select>
                  </el-form-item>
                  <el-form-item label-width="50px" label="数量" v-if="!startsWith(item.specification)">
                    <el-input filterable clearable v-model.number="item.count" style="width:120px"></el-input>
                  </el-form-item>
                </div>
                <div style="display: flex;margin-right: 30px">
                  <el-form-item style="margin-right: 10px">
                    <el-button type="danger" @click="delCode(item,index)">删除</el-button>
                   </el-form-item>
                   <el-form-item v-if="index == 0">
                     <el-button type="success" @click="addCode">增加</el-button>
                   </el-form-item> 
                </div>
               </div>
               <div style="display: flex;">
                <el-form-item label-width="80px" label="品名">
                  <el-input disabled clearable v-model="item.technologyName" style="width:220px"></el-input>
                </el-form-item>
                <el-form-item label-width="50px" label="规格">
                  <!-- <el-input disabled filterable clearable v-model="item.specification" style="width:100px"></el-input> -->
                  <el-select filterable clearable style="width:120px" v-model="item.specification"  @change="GGChange($event,index)" placeholder="规格">
                      <el-option :value="item1.MB003" :label="item1.MB003" v-for="(item1,index1) in materialCodeList" :key="index1"/>
                    </el-select>
                </el-form-item>
                <el-form-item style="margin-left:5px;">
                  <el-button type="warning" @click="GGclick(index)">添加规格</el-button>
                </el-form-item>
              </div>
              <div v-if="item.specification && (item.specification.startsWith('0409') || item.specification.startsWith('0407') || item.specification.startsWith('0415'))">
                 <div style="display: flex;" v-for="(elm,id) in item.types" :key="id">
                   <el-form-item label-width="100px" label="电缆类型">
                     <!-- <el-input clearable v-model="item.cableType" style="width:200px"></el-input> -->
                     <el-select filterable clearable style="width:200px" v-model="elm.type" placeholder="请选择电缆类型">
                       <el-option :value="item1.id" :label="item1.name" v-for="(item1,index1) in cableTypeList" :key="index1"/>
                     </el-select>
                   </el-form-item>
                   <el-form-item label-width="50px" label="根数">
                     <el-input clearable v-model.number="elm.count" style="width:120px"></el-input>
                   </el-form-item>
                   <el-form-item style="margin: 0 10px 0 10px;">
                    <el-button type="danger" icon="el-icon-delete" v-if="id !== 0" circle @click="delType(index,elm,id)"></el-button>
                   </el-form-item>
                   <el-form-item style="margin: 0 10px 0 10px;" v-if="id == 0">
                      <el-button type="success" icon="el-icon-plus" circle @click="addType(index)"></el-button>
                   </el-form-item> 
                 </div>
               </div>
               <div v-if="item.specification && (item.specification.startsWith('2101') || item.specification.startsWith('2102'))">
                 <div style="display: flex;" v-for="(elm,id) in item.materials" :key="id">
                   <el-form-item label-width="100px" label="物料类型">
                     <!-- <el-input clearable v-model="item.cableType" style="width:200px"></el-input> -->
                     <el-select @focus="focusWL" filterable clearable style="width:200px" v-model="elm.materialClass" placeholder="请选择物料类型">
                       <el-option :value="item1.materialClass" :label="item1.materialClass" v-for="(item1,index1) in materialList" :key="index1"/>
                     </el-select>
                   </el-form-item>
                   <el-form-item label-width="50px" label="数量">
                     <el-input clearable v-model.number="elm.count" style="width:120px"></el-input>
                   </el-form-item>
                   <el-form-item style="margin: 0 10px 0 10px;">
                    <el-button type="danger" icon="el-icon-delete" v-if="id !== 0" circle @click="delmaterial(index,elm,id)"></el-button>
                   </el-form-item>
                   <el-form-item style="margin: 0 10px 0 10px;" v-if="id == 0">
                      <el-button type="success" icon="el-icon-plus" circle @click="addmaterial(index)"></el-button>
                   </el-form-item> 
                 </div>
               </div>
             </div>
             <el-form-item style="margin-top:30px;margin-left: 500px;">
              <el-button type="primary" @click="typeSubmit">提交</el-button>
            </el-form-item>
            </el-collapse-item>
  </el-collapse>
</div>
      <el-form-item label="工作中心" :label-width="formLabelWidth" prop="workCenter">
          <el-select
          clearable
          v-model="modifyform.workCenter"
          placeholder="请选择工作中心"
          @focus="getCenterList"
          @change="workCenterChange"
          style="width:400px">
          <el-option :value="item" :label="item" v-for="(item,index) in this.centerList.data" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="部门" :label-width="formLabelWidth">
        <el-select v-model="modifyform.department" placeholder="请选择该员工当前所在部门" @focus="getDepartInfo" style="width:400px">
          <el-option :value="item" :label="item" v-for="(item,index) in this.departList" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="职级" :label-width="formLabelWidth">
        <el-cascader v-model="modifyform.jobClassStr" separator="-" :options="options" filterable clearable style="width:400px" />
      </el-form-item>
      <el-form-item label="标准工时(s)" :label-width="formLabelWidth" prop="manTimeFloat">
        <el-input clearable v-model.number="modifyform.manTimeFloat" placeholder="单位为秒的整数" style="width:400px"/>
      </el-form-item>
      <!-- <el-form-item label="重点工序" :label-width="formLabelWidth">
        <el-switch
          v-model="modifyform.proIsImport"
          active-text="是"
          inactive-text="否">
        </el-switch>
      </el-form-item> -->
      <el-form-item label="重点工序名称:" prop="proIsImportName" :label-width="formLabelWidth">
          <el-select clearable v-model="modifyform.proIsImportName" style="width:400px">
            <el-option :value="item" :label="item" v-for="(item,index) in this.importNameList" :key="index"/>
          </el-select>
      </el-form-item>
      <el-form-item label="工艺说明" :label-width="formLabelWidth">
        <el-input
          clearable
          v-model="modifyform.remark"
          type="textarea"
          autosize
          style="width:400px"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="modifyProcess">确 定</el-button>
    </div>
    </el-dialog>
    <el-dialog title="添加规格" :visible.sync="GGshow" width="30%">
      <el-form>
        <el-form-item label="规格" label-width="40px">
          <el-input
            clearable
            v-model="specification"
            style="width:200px"
          ></el-input>
          <el-button type="primary" @click="specificationQD">查询</el-button>
        </el-form-item>
      </el-form>
      <el-radio-group  v-model="radio">
        <el-radio style="display: block; margin-bottom: 8px;" :label="index" v-for="(item,index) in specificationList" :key="index">
          <span>物料编码：{{ item.CB005 }}</span>
          <div style="margin-left: 25px;">品   名：{{ item.MB002 }}</div>
        </el-radio>
      </el-radio-group>
      <div slot="footer" class="dialog-footer">
        <el-button @click="GGshow = false">取 消</el-button>
        <el-button type="primary" @click="submitGG">确 定</el-button>
      </div>
    </el-dialog>
      <!-- pagination 分页 -->
      <div class="pagination-container">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[5,10, 20, 30, 40,100,300,500]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>

    <el-divider></el-divider>
    <el-button style="margin-right: 10px" type="success" size="small" @click="hExportExcel">导出数据Excel</el-button>
    <el-button type="success" size="small" @click="getExcelList">下载Excel模板</el-button>
    <el-divider></el-divider>

    <!-- 上传Excel表单 -->
    <div style="display: flex;">
      <el-upload
        class="upload-demo"
        ref="upload"
        :action="userInfo.roleId == '35' || userInfo.roleId == '36'?baseURL+'/back/processJobClass/EmsprocessExcel':baseURL+'/back/processJobClass/processExcel'"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :on-success="handleSuccess"
        :on-error="handleError"
        :headers="httpHeader"
        :file-list="fileList"
        :show-file-list="showfilelist"
        :auto-upload="false"
        v-if="userInfo.roleId != 30 && userInfo.roleId != 37 && userInfo.roleId != 16">
        <el-button slot="trigger" size="small" type="primary">选取工序文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload(1)" :loading="uploadLoading">{{uploadTip}}</el-button>
        <div slot="tip" class="el-upload__tip">将Excel表单从此处上传到服务器</div>
      </el-upload>

      <el-upload
      style="margin-left: 30px;"
      v-if="userInfo.roleId == '35' || userInfo.roleId == '36' || userInfo.roleId == '14'"
      ref="upload2"
        class="upload-demo"
        :action="baseURL + '/back/processJobClass/EmsProcessMoneyConfigExcel'"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :on-success="handleSuccess2"
        :on-error="handleError"
        :headers="httpHeader"
        :file-list="fileList"
        :show-file-list="showfilelist"
        :auto-upload="false">
        <el-button slot="trigger" size="small" type="primary">上传工艺工序及其计件参数</el-button>
        <el-button style="margin-left: 10px;" size="small" @click="submitUpload(2)" :loading="uploadLoading" type="success">{{uploadTip}}</el-button>
      </el-upload>

    </div>
    </div>
</template>

<script>
import { findMaterialClassGroupBy,addProcess, getProcessList, changeProcessRank, delProcess,upIsDelete,seldplate,groupProcessNo,moneyConfigFind,moneyConfigUpd,processJobClassFind,findChineseDescription,moneyConfigDel} from '../../api/processRoute'
import {getCenter } from '../../api/workSection.js'
import { getRoleList,getDepartList } from '@/api/user'
import {uploadURL,baseURL} from '@/utils/baseURL'
import { getToken } from '@/utils/auth'
export default {
    name: 'add_ProcessRoute',
    data() {
      return {
        GGindex:'',
        radio:0,
        specificationList:[],    // 获取的规格列表
        specification:'',        // 规格
        GGshow: false,
        fileList:[],
        uploadURL: uploadURL,
        baseURL: baseURL,
        // 岗位职级下拉选项
        options: [{
          value: 'O1',
          label: 'O1',
          children: [{
            value: '1',
            label: '1'
          }, {
            value: '2',
            label: '2'
          }, {
            value: '3',
            label: '3'
          }, {
            value: '4',
            label: '4'
          }, {
            value: '5',
            label: '5'
          }]
        }, {
          value: 'O2',
          label: 'O2',
          children: [{
            value: '1',
            label: '1'
          }, {
            value: '2',
            label: '2'
          }, {
            value: '3',
            label: '3'
          }, {
            value: '4',
            label: '4'
          }, {
            value: '5',
            label: '5'
          }]
        }, {
          value: 'O3',
          label: 'O3',
          children: [{
            value: '1',
            label: '1'
          }, {
            value: '2',
            label: '2'
          }, {
            value: '3',
            label: '3'
          }, {
            value: '4',
            label: '4'
          }, {
            value: '5',
            label: '5'
          }]
        },  {
          value: 'O4',
          label: 'O4',
          children: [{
            value: '1',
            label: '1'
          }, {
            value: '2',
            label: '2'
          }, {
            value: '3',
            label: '3'
          }, {
            value: '4',
            label: '4'
          }, {
            value: '5',
            label: '5'
          }]
        }, {
          value: 'O5',
          label: 'O5',
          children: [{
            value: '1',
            label: '1'
          }, {
            value: '2',
            label: '2'
          }, {
            value: '3',
            label: '3'
          }, {
            value: '4',
            label: '4'
          }, {
            value: '5',
            label: '5'
          }]
        }],
        technologyNo: '',                                               //产品编号——添加时使用
        listQuery: {
          technologyNo: '',                                             //产品编号
          processNo: '',                                                //工序编号
          processName: '',                                              //工序名称
          workCenter: '',                                               //工作中心
          department: '',                                               //部门
          jobClass: [],                                                 //职级
          page: 1,                                                      //页码
          limit: 10                                                     //每页默认信息条数
        },
        modifyform: {                                                   //工艺信息修改表单
          processId: '',                                                //工序ID
          department: '',                                               //部门
          jobClassStr: [],                                               //职级
          manTimeFloat: '',
          technologyNo: '',                                               //品号
          proIsImport: '',                                                    //是否重点工序  0非重点  1重点
          processOrder: '',
          processName: '',
          knife: '',
          manTime: '',
          workCenter: '',
          proIsImportName: '',
          remark: '',
          actionAbbreviation:'',  //工序动作
          emsCoefficientType:''
        },
        dealList: [],
        total: 0,       //总的信息条目数
        dialogFormVisible: false,                                       //工艺信息修改表单开启与关闭的条件
        formLabelWidth: '120px',                                        //工艺信息修改表单输入框宽度
        departList: {},
        listLoading: false,                                             //工艺路线列表开启与关闭的条件
        loadingBtn: false,
        searchLoadingBtn: false,
        httpHeader: {
            'Authorization': ''
        },
        centerList: '',                       //获取工作中心的列表
        rules: {},
        userInfo: this.$store.state.user.userInfo,
        uploadLoading: false,
        uploadTip:'上传到服务器',
        showfilelist: true,
        optionsYS: ['否','是'],
        processNameGzList: ['压铆','攻牙','钻孔','沉孔','涂漆','滚圆','拉铆','拉丝','撕胶纸','倒角','去毛刺','扩孔','震磨'],
        textureList: [],
        processList: [],
        height: 670,
        importNameList: ['打胶','功率螺钉紧固','关键尺寸控制','试水','市场投诉问题','接线','安规测试'],
        limitField: [
                {
                    name: '铆钉数量',
                    showList: ['压铆','拉铆','镀铆','自动压铆','焊接拉铆']
                },
                {
                    name: '加工次数',
                    showList: ['普冲','钻孔','沉孔','滚圆','攻丝','倒钝','倒角','去毛刺','扩孔','震磨','攻牙','涂漆','拉丝','机加','光纤激光打标','撕胶纸','自动攻钻','CNC加工中心','校正','走心机','打磨校正','暗室检验','热缩套管','刮灰','丝印','套管','木作','自动丝印']
                },
                {
                    name: '板材',
                    showList: ['雕刻机']
                },
                {
                    name: '刀数',
                    showList: ['数折']
                },
                {
                    name: '连焊长度',
                    showList: ['焊缝清洗','人工焊接','机器人焊接','氩焊焊接','手持激光焊','打磨','自动打磨','清焊渣','冷焊','机器人激光焊','焊接编程','组焊','机器人组打磨']
                },
                {
                    name: '焊点数量',
                    showList: ['焊缝清洗','人工焊接','机器人焊接','氩焊焊接','手持激光焊','打磨','自动打磨','清焊渣','冷焊','机器人激光焊','焊接编程','组焊','机器人组打磨']
                },
                {
                    name: '碰焊点数',
                    showList: ['碰焊','打磨','自动打磨','清焊渣','机器人组打磨']
                },
                {
                    name: '外购件数量',
                    showList: ['装配']
                },
                {
                    name: '螺钉数量',
                    showList: ['装配']
                },
                {
                    name: '打胶长度',
                    showList: ['装配']
                },
                {
                    name: '不锈钢螺钉数量',
                    showList: ['装配']
                },
                {
                    name: '功率螺钉数量',
                    showList: ['装配']
                },
                {
                    name: '零件数量',
                    showList: ['装配']
                },
                {
                    name: '喷涂面积',
                    showList: ['上挂'] // ,'清洁','打底','补喷','自检','修补','落件','吊机操作','下挂','补漆'
                },
                {
                    name: '保护面积',
                    showList: ['喷保'] // ,'拆保护'
                },
                {
                    name: '保护个数',
                    showList: ['喷保']  // ,'拆保护'
                },
          ],
        processAction: [
          {
          name:'装配',
          id:'ZP'
          },
          {
          name:'包装',
          id:'BZ'
          },
          {
          name:'粘贴',
          id:'ZT'
          },
          {
          name:'测试',
          id:'CS'
          },
          {
          name:'绑扎',
          id:'BZ'
          },
          {
          name:'检查',
          id:'JC'
          }],   // 工序动作列表
        processActionMin:[],    // 工序小类列表
        typeList: [{             // 物料编码类型列表
          elementTechnologyNo:'',
          count:'',
          types:[{count:'',type:''}],
          materials:[{count:'',materialClass:''}]
        }],
        // types:[{count:'',type:''}],
        materialCodeList:[{elementTechnologyNo:''}], // 物料编码列表
        cableTypeList:[
          {
            name:'(L<=2M且Q<=10)',
            type:'电子电力线缆',
            id:'01'
          },
          {
            name:'(L<=2M且Q>10)',
            type:'电子电力线缆',
            id:'04'
          },{
            name:'(3M<L且Q>10)',
            type:'电子电力线缆',
            id:'06'
          },{
            name:'(2M<L<=3M且Q<=10)',
            type:'线束',
            id:'02'
          },{
            name:'(3M<L且Q<=10)',
            type:'线束',
            id:'03'
          },{
            name:'(2M<L<=3M且Q>10)',
            type:'线束',
            id:'05'
          }
        ],
        keywordList:[{   // 对外中文说明关键字对应类型
          name:'机柜',
          showList:['机柜','室内','混合电源','机房电源','电池柜','室外','机框','电源系统','混合供电','充电','终端','机架']
        },
        {
          name:'插框',
          showList:['嵌入','插框']
        },
        {
          name:'盒体',
          showList:['单元','盒']
        },
        {
          name:'辅料包',
          showList:['辅料']
        }
        ], 
        fficientTypeList: {    // 系数类型列表合计
          '机柜':['A1','A2','A3','A4','A5'],
          '插框':['B1','B2','B3','B4','B5'],
          '盒体':['C1','C2','C3','C4','C5'],
          '辅料包':['D1','D2','D3','D4','D5']
        },
        coefficientList:[], // 系数类型列表
        fficientType:'',
        materialList:[
          // '门板',
          // '汇流排',
          // '电缆标签',
          // '标准紧固件',
          // '钣金件',
          // '管夹',
          // '快速标记条',
          // 'PC盖板',
          // '防水PG头',
          // 'HUAWEILOGO标签',
          // '机柜来料附件',
          // '非金属件',
          // '绝缘材料',
          // '生产标签',
          // '产品标签',
          // '附件',
          // '非标紧固件',
          // '卡箍',
        ]
      }
    },
    methods: {
      // 获取物料类型
      async focusWL(){
        const res = await findMaterialClassGroupBy()
        this.materialList = res.data
      },
      // 规格点确定
      submitGG(){
        if(!this.specification) return this.$message.warning('规格不能为空')
        if(!this.specificationList.length) return this.$message.warning('未查到对应规格选项')
        this.typeList[this.GGindex].elementTechnologyNo = this.specificationList[this.radio].CB005
        this.typeList[this.GGindex].technologyName = this.specificationList[this.radio].MB002
        this.typeList[this.GGindex].specification = this.specificationList[this.radio].MB003
        this.specificationList = []
        this.specification = ''
        this.GGshow = false
      },
      // 查看规格
      async specificationQD(){
        const query = {
          specification: this.specification
        }
        const res = await processJobClassFind(query)
        console.log(res)
        this.specificationList = res.data
      },
      GGclick(index){
        this.GGshow = true
        this.GGindex = index
      },
      startsWith(num) {
      // 使用正则表达式检查字符串是否以0409|0407|0415|2101|2102开头
      return /^(0409|0407|0415|2101|2102)/.test(num);
    },
    // 删除物料类型
    async delmaterial(index,elm,id){
        if(this.typeList[index].materials.length == 1 && elm.id){
          this.typeList[index].materials = [{materialClass:'',count:''}]
          const res = await moneyConfigDel({id:elm.id})
          this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
            return 
        }
        if(elm.id){
          this.typeList[index].materials.splice(id, 1);
          const res = await moneyConfigDel({id:elm.id})
          this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
            return 
        }
        if(!elm.id){
          this.typeList[index].materials.splice(id, 1);
        }
      },
      // 删除电缆
      async delType(index,elm,id){
        // console.log(elm);
        // console.log(this.typeList[index].types);
        if(this.typeList[index].types.length == 1 && elm.id){
          this.typeList[index].types = [{type:'',count:''}]
          const res = await moneyConfigDel({id:elm.id})
            this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
            return 
        }
        if(elm.id){
          this.typeList[index].types.splice(id, 1);
          const res = await moneyConfigDel({id:elm.id})
          this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
            return 
        }
        if(!elm.id){
          this.typeList[index].types.splice(id, 1);
        }
      },
      // 添加电缆
      addType(index){
        this.typeList[index].types.push({
          count:'',
          type:'',
        })
      },
      // 添加物料类型
      addmaterial(index){
        this.typeList[index].materials.push({
          materialClass:'',
          type:'',
        })
      },
      // 删除编码
      async delCode(item,index){
        if(this.typeList[index].types[0].type){
          this.typeList[index].types.forEach(async elm =>{
            const res = await moneyConfigDel({id:elm.id})
            this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
          })
          if(this.typeList.length !== 1){
            this.typeList.splice(index, 1);
          } else if(this.typeList.length == 1) {
            this.typeList = [{
            processId:this.modifyform.processId,
            technologyNo:this.modifyform.technologyNo,
            processOrder:this.modifyform.processOrder,
            elementTechnologyNo:'',
            count:'',
            materials: [{count:'',materialClass:''}],
            types:[{type:'',count:''}]}]
          }
          return
        }
        if(this.typeList[index].materials[0].materialClass){
          this.typeList[index].materials.forEach(async elm =>{
            const res = await moneyConfigDel({id:elm.id})
            this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
          })
          if(this.typeList.length !== 1){
            this.typeList.splice(index, 1);
          } else if(this.typeList.length == 1) {
            this.typeList = [{
            processId:this.modifyform.processId,
            technologyNo:this.modifyform.technologyNo,
            processOrder:this.modifyform.processOrder,
            elementTechnologyNo:'',
            count:'',
            materials: [{count:'',materialClass:''}],
            types:[{type:'',count:''}]}]
          }
          return
        }
        if(!item.id) {
          if(this.typeList.length == 1){
            this.typeList = [{
            processId:this.modifyform.processId,
            technologyNo:this.modifyform.technologyNo,
            processOrder:this.modifyform.processOrder,
            elementTechnologyNo:'',
            count:'',
            materials: [{count:'',materialClass:''}],
            types:[{type:'',count:''}]}]
          } else {
            this.typeList.splice(index, 1);
          }
            return 
        }
        if(this.typeList.length == 1){
          this.typeList = [{
            processId:this.modifyform.processId,
            technologyNo:this.modifyform.technologyNo,
            processOrder:this.modifyform.processOrder,
            elementTechnologyNo:'',
            count:'',
            materials: [{count:'',materialClass:''}],
            types:[{type:'',count:''}]}]
            const res = await moneyConfigDel({id:item.id})
            this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
          } else {
          this.typeList.splice(index, 1);
          const res = await moneyConfigDel({id:item.id})
          this.$message({
                message: res.code == 1 ? '删除成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
        }
      },
      // 添加条码
      addCode(){
        this.typeList.push({
          processId:this.modifyform.processId,
          technologyNo:this.modifyform.technologyNo,
          processOrder:this.modifyform.processOrder,
          elementTechnologyNo:'',
          count:'',
          types:[{type:'',count:''}],
          materials:[{materialClass:'',count:''}],
        })
        console.log(this.typeList);
      },
      // 物料编码发生改变
      logyNoChange(e,index){
        console.log(this.materialCodeList);
        this.materialCodeList.forEach(item => {
          // console.log(item);
          if(item.CB005.trim() == e.trim()) {
            this.typeList[index].specification = item.MB003
            this.typeList[index].technologyName = item.MB002
          }
        })
        this.typeList[index].types = [{type:'',count:''}]
        console.log(this.typeList);
      },
       // 规格发生改变
       GGChange(e,index){
        console.log(this.materialCodeList);
        this.materialCodeList.forEach(item => {
          // console.log(item);
          if(item.MB003.trim() == e.trim()) {
            this.typeList[index].technologyName = item.MB002
            this.typeList[index].elementTechnologyNo = item.CB005
          }
          if(!e){
            this.typeList[index].technologyName = ''
            this.typeList[index].elementTechnologyNo = ''
          }
        })
        this.typeList[index].types = [{type:'',count:''}]
        console.log(this.typeList);
      },
      // 类型提交
       typeSubmit(){
        for (const item of this.typeList) {
          if(!item.specification) return this.$message.error('规格不能为空')
          if(!item.elementTechnologyNo) return this.$message.error('物料编码不能为空')
          if(item.specification){
            const bool = item.specification.startsWith('0409') || item.specification.startsWith('0407') || item.specification.startsWith('0415') || item.specification.startsWith('2101') || item.specification.startsWith('2102')
            if(!bool && !item.count){
               return this.$message.error('数量不能为空')
            } else if(bool){
              if(item.specification.startsWith('0409') || item.specification.startsWith('0407') || item.specification.startsWith('0415')){
                for (const elm of item.types){
                  if(!elm.type) return this.$message.error('电缆类型不能为空')
                  if(!elm.count) return this.$message.error('电缆数量不能为空')
                }
              } else if(item.specification.startsWith('2101') || item.specification.startsWith('2102')){
                for (const elm of item.materials){
                  if(!elm.materialClass) return this.$message.error('物料类型不能为空')
                  if(!elm.count) return this.$message.error('物料数量不能为空')
                }
              }
            }
          }
        }
        this.typeList.forEach(async item => {
          if(item.types[0].type){
            const query1 = {}
            item.types.forEach(async elm => {
              console.log(elm);
              query1.id = elm.id
              query1.type = elm.type
              query1.count = elm.count
              query1.processId = this.modifyform.processId
              query1.technologyNo = this.modifyform.technologyNo
              query1.processOrder = this.modifyform.processOrder
              query1.processName = this.modifyform.processName
              query1.elementTechnologyNo = item.elementTechnologyNo
              query1.specification = item.specification
              query1.technologyName = item.technologyName
              console.log(query1);
              const res = await moneyConfigUpd(query1)
              console.log(res);
              this.$message({
                message: res.code == 1 ? '添加成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
              })
          }else if(item.materials[0].materialClass){
            const query1 = {}
            item.materials.forEach(async elm => {
              query1.id = elm.id
              query1.type = elm.type
              query1.count = elm.count
              query1.materialClass = elm.materialClass
              query1.processId = this.modifyform.processId
              query1.technologyNo = this.modifyform.technologyNo
              query1.processOrder = this.modifyform.processOrder
              query1.processName = this.modifyform.processName
              query1.elementTechnologyNo = item.elementTechnologyNo
              query1.specification = item.specification
              query1.technologyName = item.technologyName
              console.log(query1);
              const res = await moneyConfigUpd(query1)
              console.log(res);
              this.$message({
                message: res.code == 1 ? '添加成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
              })
          } else {
            let query = Object.assign({},item)
            query.processId = this.modifyform.processId,
            query.technologyNo = this.modifyform.technologyNo,
            query.processOrder = this.modifyform.processOrder
            query.processName = this.modifyform.processName
            delete query.types
            delete query.materials
            console.log(query);
            const res = await moneyConfigUpd(query)
            console.log(item,res);
            this.$message({
                message: res.code == 1 ? '添加成功' : res.msg,
                type: res.code == 1 ? 'success' : 'warning',
              })
          }
        })
        setTimeout(async() =>{
          await this.getMaterial(this.modifyform.technologyNo,this.modifyform.processOrder)
        },1000)
      },
      // 获取系数类型列表
      async coefficientFocus(){
        const res = await findChineseDescription({technologyNo:this.modifyform.technologyNo})
        if(!res.data[0].chinese) return this.$message.warning('没维护中文说明关键字')
          let type = ''
          this.keywordList.forEach(item => {
            item.showList.forEach(item1 =>{
              if(res.data[0].chinese.includes(item1)){
                type = item.name
              }
            })
          })
          this.coefficientList = this.fficientTypeList[type]
      },
      // 工序动作改变
      setProcessActionNo(e){
        if(e == '装配'){
          this.processActionMin = ['装配1','装配2','装配3','装配4','装配5']
        } else if(e == '包装'){
          this.processActionMin = ['包装1','包装2','包装3','包装4','包装5']
        } else if(e == '粘贴'){
          this.processActionMin = ['粘贴1','粘贴2','粘贴3','粘贴4','粘贴5']
        } else if(e == '测试'){
          this.processActionMin = ['测试1','测试2','测试3','测试4','测试5']
        } else if(e == '绑扎'){
          this.processActionMin = ['绑扎1','绑扎2','绑扎3','绑扎4','绑扎5']
        } else if(e == '检查'){
          this.processActionMin = ['检查1','检查2','检查3','检查4','检查5']
        }
        this.modifyform.processNameGz = this.processActionMin[0]
      },
      // 工作中心改变
      workCenterChange(e){
        console.log(e)
        // if(e.trim() !== 'EMS总装车间'){
        //   console.log(this.processList);
        //   const bool = this.processList.some(item => {
        //     this.modifyform.processName == item.processName && this.modifyform.processNo == item.processNo
        //     this.modifyform.workCenter == item.workCenter
        //   })
        //   console.log(bool);
        //   if(!bool) {
        //     console.log('不能');
        //   } else {
        //     console.log('能');
        //   }
        // }
      },
      showOrhide(key){
          var numReg = /^[0-9]*$/
          var numRe = new RegExp(numReg)
          let showFlag = false
          if(this.modifyform.processName.indexOf('钳铆') == 0 || this.modifyform.workCenter == '喷涂车间'){
            showFlag = this.limitField.some(item => item.name == key && item.showList.some(item1 => this.modifyform.processNameGz == item1 || this.modifyform.processNameGz.indexOf(item1) == 0 && numRe.test(this.modifyform.processNameGz.split(item1)[1])))
          } else {
            showFlag = this.limitField.some(item => item.name == key && item.showList.some(item1 => this.modifyform.processName == item1 || this.modifyform.processName.indexOf(item1) == 0 && numRe.test(this.modifyform.processName.split(item1)[1])))
          }
          return showFlag
      },
      // 获取工作中心
      async getCenterList() {
        let query = {}
        // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
        console.log(111);
        const data = await getCenter(query)
        this.centerList = data
        this.centerList.data.forEach((item,index) => {
          if(item.trim() == '焊喷车间'){ this.centerList.data.splice(index,1) }
        });
      },
    submitUpload(id) {
      this.uploadLoading = true
      this.uploadTip = '正在上传中'
      this.showfilelist = false
      // this.httpHeader.Authorization = this.dealCookie(document.cookie)
      this.httpHeader.Authorization = getToken()
      if(id == 1){
        this.$refs.upload.submit()
      } else {
        this.$refs.upload2.submit()
      }

    },
    // cookies的处理函数
    dealCookie(value) {
        const cookieArr = value.split('=')
        // 测试服使用cookieArr[2]
        return cookieArr[1]
    },
    handleError(){
      this.uploadLoading = false
      this.showfilelist = true
      this.uploadTip = '上传到服务器'
      this.$message({
        type: 'error',
        message: '上传失败!'
      })
    },
    handleSuccess(response) {
       console.log(response,'response')
       const result = response.code
       const errMsg = response.msg
       this.uploadLoading = false
       this.showfilelist = true
       this.uploadTip = '上传到服务器'
       this.$refs['upload'].clearFiles()
        if(result == '1'){
            this.$message({
              type: 'success',
              message: errMsg
          })
          this.handleFilter()
        }else{
            this.$message({
              type: 'error',
              message: errMsg
        })
      }
    },
    handleSuccess2(response) {
       console.log(response,'response')
       const result = response.code
       const errMsg = response.msg
       this.uploadLoading = false
       this.showfilelist = true
       this.uploadTip = '上传到服务器'
       this.$refs['upload2'].clearFiles()
        if(result == '1'){
            this.$message({
              type: 'success',
              message: errMsg
          })
          this.handleFilter()
        }else{
            this.$message({
              type: 'error',
              message: errMsg
        })
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    // 添加工艺路线函数
    async addProcessBtn() {
      this.loadingBtn = true
      let query = {
        technologyNo: this.technologyNo
      }
      // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
      const data = await addProcess(query)
      const errMsg = data.msg
      if(data.code == '1'){
        this.$message({
          message: '添加成功',
          type: 'success'
        })
        this.listQuery.technologyNo = this.technologyNo                     // 实现功能：当添加工艺路线时，点击添加直接呈现添加的工艺路线，方便用户修改
        this.listQuery.technologyEnd = this.technologyNo
        this.handleFilter()
      } else if (data.code == '2'){
          this.$message({
          message: data.msg,
          type: 'warning'
        })
      }
      this.loadingBtn = false
    },
    // 获取工艺路线列表,搜索按钮绑定函数
    async handleFilter() {
      this.searchLoadingBtn = true
      this.listLoading = true
      let query = Object.assign({}, this.listQuery)
      // 对职级数组进行处理之前先对jobClass数组做判断
      if(this.listQuery.jobClass.length == 0){
        query.jobClass = ''
      } else {
        query.jobClass = this.listQuery.jobClass.join('-')
      }
      if(this.listQuery.isDelete){ query.isDelete = this.listQuery.isDelete == '是'?'1':'0' }
      // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
      const {data} = await getProcessList(query)
      this.dealList = data.records
      this.dealList.forEach(item => {
        item.isDelete = item.isDelete == '1'?true:false
        item.manTime = (item.manTime/60).toFixed(2)
      });
      console.log('addProcessRoute',this.dealList);
      this.total = data.total
      this.listLoading = false
      this.searchLoadingBtn = false
      if(this.dealList.length<10){this.height = ''} else {this.height = 670}
    },
    // 点击修改按钮，将table表的内容传入弹框内部的表单
    // item为一行的表单数据，为一个对象
    //item中的jobClassStr值存在两种情况：第一种是null，另一种为字符串
    async handleEdit(item) {
      this.coefficientList = []
      this.modifyform.processId = item.processId
      this.modifyform.department = item.department
      this.modifyform.manTimeFloat = item.manTimeFloat?item.manTimeFloat:''
      this.modifyform.technologyNo = item.technologyNo
      this.modifyform.processOrder = item.processOrder
      this.modifyform.processName = item.processName
      this.modifyform.knife = item.knife
      this.modifyform.manTime = parseInt(item.manTime*60)
      this.modifyform.workCenter = item.workCenter
      this.modifyform.remark = item.remark
      this.modifyform.proIsImport = item.proIsImport?true:false,
      this.modifyform.actionAbbreviation = item.actionAbbreviation
      this.modifyform.emsCoefficientType = item.emsCoefficientType
      // this.modifyform.processNameGz = item.processNameGz
      // this.modifyform.weldLength = item.weldLength
      // this.modifyform.weldingSpot = item.weldingSpot
      // this.modifyform.buttJoint = item.buttJoint
      this.$set(this.modifyform, 'processNo', item.processNo)
      this.$set(this.modifyform, 'processNameGz', item.processNameGz)
      this.$set(this.modifyform, 'rivetCount', item.rivetCount)
      this.$set(this.modifyform, 'texture', item.texture)
      this.$set(this.modifyform, 'processCount', item.processCount)
      this.$set(this.modifyform, 'weldLength', item.weldLength)
      this.$set(this.modifyform, 'weldingSpot', item.weldingSpot)
      this.$set(this.modifyform, 'buttJoint', item.buttJoint)
      this.$set(this.modifyform, 'protectionNumber', item.protectionNumber)
      this.$set(this.modifyform, 'ptProtectionArea', item.ptProtectionArea)
      this.$set(this.modifyform, 'partArea', item.partArea)
      if(item.proIsImport){ this.$set(this.modifyform, 'proIsImportName', item.proIsImportName) }
      else { this.modifyform.proIsImportName = ''}
      if(item.workCenter.trim() == '装配车间' || item.workCenter.trim() == '结构总装车间' || item.workCenter.trim() == '总装车间' || item.workCenter.trim() == '医疗车间' || item.workCenter.trim() == '数控车间' || item.workCenter.trim() == '油烟机车间' || item.workCenter.trim() == '油烟机专线车间'){
        this.$set(this.modifyform, 'assembleConfig1', item.assembleConfig1)
        this.$set(this.modifyform, 'assembleConfig2', item.assembleConfig2)
        this.$set(this.modifyform, 'assembleConfig3', item.assembleConfig3)
        this.$set(this.modifyform, 'assembleConfig4', item.assembleConfig4)
        this.$set(this.modifyform, 'assembleConfig5', item.assembleConfig5)
        this.$set(this.modifyform, 'assembleConfig6', item.assembleConfig6)
      } else {
        this.modifyform.assembleConfig1 = ''
        this.modifyform.assembleConfig2 = ''
        this.modifyform.assembleConfig3 = ''
        this.modifyform.assembleConfig4 = ''
        this.modifyform.assembleConfig5 = ''
        this.modifyform.assembleConfig6 = ''
      }
      if(item.jobClass == null) {                                //当jobClass为空时，修改表单的职级赋予一个空数组
        this.modifyform.jobClassStr = []
      } else {
        this.modifyform.jobClassStr = item.jobClass.split('-')
      }
      console.log('item',item);
      this.getMaterial(item.technologyNo,item.processOrder)
      const res = await processJobClassFind({technologyNo:item.technologyNo})
      this.materialCodeList = res.data
      // this.materialCodeList = res.data.list
      this.dialogFormVisible = true
    },
    async getMaterial(technologyNo,processOrder){
      const rs = await moneyConfigFind({technologyNo:technologyNo,processOrder:processOrder, page:1,limit:9999})
      if(rs.data.list.length) {
        // const arr = rs.data.list.filter(item => !item.type)
        // console.log('arr',arr);
        const result = [];
        const map = new Map()
        rs.data.list.forEach((item,index) => {
          if (item.type && item.type !== '00') {
            const key = item.elementTechnologyNo;
            if (!map.has(key)) {
              map.set(key, {
                processId: item.processId,
                technologyNo: item.technologyNo,
                processOrder: item.processOrder,
                processName: item.processName,
                elementTechnologyNo: item.elementTechnologyNo,
                specification: item.specification,
                technologyName: item.technologyName,
                types: [],
                materials: [{count:'',materialClass:''}],
              });
              result.push(map.get(key));
            }
            map.get(key).types.push({ type: item.type, count: item.count,id:item.id,createTime:item.createTime });
          }else if (item.materialClass) {
            const key = item.elementTechnologyNo;
            if (!map.has(key)) {
              map.set(key, {
                processId: item.processId,
                technologyNo: item.technologyNo,
                processOrder: item.processOrder,
                processName: item.processName,
                elementTechnologyNo: item.elementTechnologyNo,
                specification: item.specification,
                technologyName: item.technologyName,
                count: item.count,
                types: [{type:'',count:''}],
                materials: [],
              });
              result.push(map.get(key));
            }
            map.get(key).materials.push({ materialClass: item.materialClass, count: item.count,id:item.id,createTime:item.createTime });
          } else {
            result.push({
              count:item.count,
              createTime:item.createTime,
              elementTechnologyNo:item.elementTechnologyNo,
              gross:item.gross,
              id:item.id,
              limit:item.limit,
              orderGross:item.orderGross,
              page:item.page,
              processName:item.processName,
              processId:item.processId,
              processOrder:item.processOrder,
              specification:item.specification,
              tb005:item.tb005,
              technologyName:item.technologyName,
              technologyNo:item.technologyNo,
              type:item.type,
              count: item.count,
              types:[{type:'',count:''}],
              materials:[{count:'',materialClass:''}],
            });
          }
        })
        this.typeList = result
        console.log('result',result)
      } else {
        this.typeList = [{ elementTechnologyNo:'',count:'',types:[{count:'',type:''}],materials:[{count:'',materialClass:''}]}]
      }
    },
    handleDelete(index,row) {
      this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(async () => {
          let query = {
            processId: row.processId
          }
          // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
          let res = await delProcess(query)
          this.dealList.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 工艺经理审核通过
    upDateProcess(index,row){
      console.log(this.userInfo)
      if(this.userInfo.roleId == 0 || this.userInfo.roleId == 14 || this.userInfo.roleId == 27 || this.userInfo.roleId == 36){
        let msg = ''
        if(!row.isDelete) {
          msg = '确定修改审核结果为【不通过】?'
        } else {
          msg = '确定工艺信息无误?'
        }
        this.$confirm(msg, '警告', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
          }).then(async () => {
            let query = {
              technologyNo: row.technologyNo,
              isDelete: row.isDelete?'1':'0'
            }
            // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
            let data = await upIsDelete(query)
            let errmsg = data.msg
            if(data.code == '1'){
              this.handleFilter()
              this.$message({
                type: 'success',
                message: errmsg
              })
            } else {
              this.$message({
                type: 'warning',
                message: errmsg
              })
            }
          }).catch(() => {
            this.dealList[index].isDelete = !this.dealList[index].isDelete
            this.$message({
              type: 'info',
              message: '已取消'
            })
          })
      } else {
        this.$message({
          message: '请联系工艺经理进行处理！',
          type: 'warning'
        })
        this.dealList[index].isDelete = !this.dealList[index].isDelete
      }
    },
    // 获取部门函数
    async getDepartInfo() {
        let query = {}
        // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
        let {data} = await getDepartList()
        this.departList = data
    },
      // 将弹框修改后的工艺信息传入后台，并且消息提示是否修改成功
      // 当职级与部门都为空需要添加时，只添加一个是无法成功提交的
      async modifyProcess() {
        if(this.modifyform.processCount>0 && this.modifyform.rivetCount>0) return this.$message.error('加工次数、螺钉数量只能选一个有值,或者其中一个为0')
        let query = {
          processId: this.modifyform.processId,
          department: this.modifyform.department,
          technologyNo: this.modifyform.technologyNo,
          manTimeFloat: this.modifyform.manTimeFloat,
          processNameGz: this.modifyform.processNameGz,
          processCount: this.modifyform.processCount?this.modifyform.processCount:0,
          rivetCount: this.modifyform.rivetCount?this.modifyform.rivetCount:0,
          texture: this.modifyform.texture,
          weldLength: this.modifyform.weldLength,
          weldingSpot: this.modifyform.weldingSpot,
          buttJoint: this.modifyform.buttJoint,
          proIsImport: this.modifyform.proIsImportName?'1':'0', 
          processOrder: this.modifyform.processOrder,
          processName: this.modifyform.processName,
          knife: this.modifyform.knife,
          manTime: this.modifyform.manTime,
          workCenter: this.modifyform.workCenter,
          remark: this.modifyform.remark,
          processNo: this.modifyform.processNo,
          partArea: this.modifyform.partArea,
          protectionNumber: this.modifyform.protectionNumber,
          ptProtectionArea: this.modifyform.ptProtectionArea,
          proIsImportName: this.modifyform.proIsImportName,
          actionAbbreviation: this.modifyform.actionAbbreviation,
          emsCoefficientType: this.modifyform.emsCoefficientType,
        }
        if(this.modifyform.jobClassStr.length == 0) {
          query.jobClass = ''
        } else {
          query.jobClass = this.modifyform.jobClassStr.join('-')
        }
        // if(!this.modifyform.proIsImport){ delete query.proIsImportName }
        // else { query.proIsImportName = this.modifyform.proIsImportName }
        // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
        if(this.modifyform.workCenter.trim() == '装配车间' || this.modifyform.workCenter.trim() == '结构总装车间' || this.modifyform.workCenter.trim() == '总装车间' || this.modifyform.workCenter.trim() == '医疗车间' || this.modifyform.workCenter.trim() == '数控车间' || this.modifyform.workCenter.trim() == '油烟机车间' || this.modifyform.workCenter.trim() == '油烟机专线车间'){
          query.assembleConfig1 = this.modifyform.assembleConfig1
          query.assembleConfig2 = this.modifyform.assembleConfig2
          query.assembleConfig3 = this.modifyform.assembleConfig3
          query.assembleConfig4 = this.modifyform.assembleConfig4
          query.assembleConfig5 = this.modifyform.assembleConfig5
          query.assembleConfig6 = this.modifyform.assembleConfig6
        }
        console.log('query',query)
        const res = await changeProcessRank(query)
        let msg = res.msg
        if(res.code == '1'){
          this.$message({
            message: msg,
            type: 'success'
          })
          // this.handleFilter()
        } else {
          this.$message({
            message: msg,
            type: 'warning'
          })
        }
        const query2 = {
          technologyNo: query.technologyNo,
          technologyEnd: query.technologyNo,
          page: 1,
          limit: 9999,
        }
        const {data} = await getProcessList(query2)
        for (const item of data.records) {
          if(query.processNameGz == '上挂'){
          console.log(this.dealList)
            if(['清洁', '打底', '烘烤', '喷粉', '补喷', '固化', '自检', '修补', '落件', '前处理上挂', '喷淋前处理', '前处理下挂', '下挂', '喷淋式前处理', '泡式前处理'].includes(item.processNameGz)){
              console.log(item)
              item.partArea = query.partArea
              item.manTime = item.manTime = parseInt(item.manTime*60)
              const elm = {
                processId: item.processId,
                department: item.department,
                technologyNo: item.technologyNo,
                manTimeFloat: item.manTimeFloat?item.manTimeFloat:'',
                processNameGz: item.processNameGz,
                processCount: item.processCount,
                rivetCount: item.rivetCount,
                weldLength: item.weldLength,
                weldingSpot: item.weldingSpot,
                buttJoint: item.buttJoint,
                proIsImport: item.proIsImportName?'1':'0', 
                processOrder: item.processOrder,
                processName: item.processName,
                knife: item.knife,
                manTime: item.manTime = parseInt(item.manTime*60),
                workCenter: item.workCenter,
                remark: item.remark,
                processNo: item.processNo,
                partArea: query.partArea,
                protectionNumber: item.protectionNumber,
                ptProtectionArea: item.ptProtectionArea,
                proIsImportName: item.proIsImportName,
                jobClass: item.jobClass,
              }
              const res = await changeProcessRank(elm)
              console.log(res)
            }
          }
          if(query.processNameGz == '喷保'){
            console.log(this.dealList)
              if(['拆保护'].includes(item.processNameGz)){
                const elm = {
                  processId: item.processId,
                  department: item.department,
                  technologyNo: item.technologyNo,
                  manTimeFloat: item.manTimeFloat?item.manTimeFloat:'',
                  processNameGz: item.processNameGz,
                  processCount: item.processCount,
                  rivetCount: item.rivetCount,
                  weldLength: item.weldLength,
                  weldingSpot: item.weldingSpot,
                  buttJoint: item.buttJoint,
                  proIsImport: item.proIsImportName?'1':'0', 
                  processOrder: item.processOrder,
                  processName: item.processName,
                  knife: item.knife,
                  manTime: item.manTime = parseInt(item.manTime*60),
                  workCenter: item.workCenter,
                  remark: item.remark,
                  processNo: item.processNo,
                  partArea: item.partArea,
                  protectionNumber: query.protectionNumber,
                  ptProtectionArea: query.ptProtectionArea,
                  proIsImportName: item.proIsImportName,
                  jobClass: item.jobClass,
                }
                const res = await changeProcessRank(elm)
                console.log(res)
              }
          }
        }
        this.dialogFormVisible = false
        this.handleFilter()
      },
      getData() {
        this.listQuery.page = 1
        this.listQuery.limit = 10
        this.handleFilter()
      },
      handleSizeChange(val) {
        this.listQuery.limit = val
        this.handleFilter()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        if(val == 5) {
          this.height = ''
        } else {
          this.height = 670
        }
        this.handleFilter()
      },
      // 下载模板表单
      getExcelList() {
        window.open('http://180.76.113.62:8110/image/portrait/example1.rar')
      },
      transformDat(res) {
      const mapInfo = {
        processId: '工序ID',
        processOrder: '加工顺序',
        technologyNo: '产品编号',
        technologyName: '品名',
        specification: '规格',
        processNo: '工序编号',
        processName: '工序名称',
        processNameGz: '工序小类',
        knife: '刀数',
        length: '长',
        wide: '宽',
        weight: '重',
        processCount: '加工次数',
        rivetCount: '铆钉数量',
        texture: '板材',
        thickness: '板厚',
        weldLength: '连焊长度',
        weldingSpot: '焊点数量',
        buttJoint: '碰焊点数',
        workCenter: '工作中心',
        manTime: '固定人时(M)',
        manTimeFloat1: '变动人时(M)',
        department: '部门',
        jobClass: '职级',
        isDelete: '审核是否通过',
        remark: '工艺说明'
      }
      // 对data进行格式化
      // 取出所有的属性名
      const props = Object.keys(res[0]) // ['id','']
      console.log(props)
      // 将属性名从英文转为中文
      const header = props.map(zhkey => mapInfo[zhkey])
      console.log('中文的表头', header)
      // const data=[['xxxx','总裁办'，'13800000']]
      const data = res.map(obj => Object.values(obj))
      console.log(data)
      return { header, data }
    },
    // 导出excel
    async hExportExcel() {
      this.loading = true
      let query = Object.assign({},this.listQuery)
      // 对职级数组进行处理之前先对jobClass数组做判断
      if(this.listQuery.jobClass.length == 0){
        query.jobClass = ''
      } else {
        query.jobClass = this.listQuery.jobClass.join('-')
      }
      query.page = 1
      query.limit = 10000
      if(this.listQuery.isDelete){ query.isDelete = this.listQuery.isDelete == '是'?'1':'0' }
      console.log('%c导出excel传的参数query:','color:green;font-size:16px;')
      console.log(query)
      // if(this.userInfo.departmentName == '喷涂车间') { query.isSpray = true }
      let arr = await getProcessList(query)
      if(arr.code != '1') return  this.$message.error(arr.msg)
      const { header, data } = this.transformDat(this.setSort(arr.data.records))
      import('@/vendor/Export2Excel').then(excel => {
        // excel表示导入的模块对象
        console.log(excel)
        excel.export_json_to_excel({
        header, // 表头 必填
        data, // 具体数据 必填
        filename: '工艺新增搜索修改-excel', // 文件名称
        autoWidth: true, // 宽度是否自适应
        bookType: 'xlsx' // 生成的文件类型
        })
      })
      this.loading = false
    },
    // 排序函数
    setSort(arr){
      let newArr = JSON.parse(JSON.stringify(arr))
      let arr1 = []
      newArr.forEach((item)=>{
        let obj = {
          processId: item.processId,
          processOrder: item.processOrder,
          technologyNo: item.technologyNo,
          technologyName: item.technologyName,
          specification: item.specification,
          processNo: item.processNo,
          processName: item.processName,
          processNameGz: item.processNameGz,
          knife: item.knife,
          length: item.length,
          wide: item.wide,
          weight: item.weight,
          processCount: item.processCount,
          rivetCount: item.rivetCount,
          texture: item.texture,
          thickness: item.thickness,
          weldLength: item.weldLength,
          weldingSpot: item.weldingSpot,
          buttJoint: item.buttJoint,
          workCenter: item.workCenter,
          manTime: item.manTime,
          manTimeFloat1: item.manTimeFloat1,
          department: item.department,
          jobClass: item.jobClass,
          isDelete: item.isDelete == '1'?'是':'否',
          remark: item.remark
      }
      arr1.push(obj)
      })
      return arr1
    },
    toAddprocess() {
      this.$router.push({
          path: 'addProcessRoute1',
          name: 'addProcessRoute1',
          params: {data: ''}
      })
    },
    async getTextureList(){
      let data = await seldplate()
      this.textureList = data.data
    },
    // 获取工艺信息
    async getprocessNo(){
        let data = await groupProcessNo()
        if(data.code == '500') return
        let errmsg = data.msg
        if(data.code == '1'){
            this.processList = data.data
        } else {
            this.$message({
                message: errmsg,
                type: 'error'
            })
        }
    },
    setProcess(e){
      if(e){
        if(this.modifyform.technologyNo.startsWith('HW') && this.modifyform.workCenter.trim() == 'EMS总装车间') {
          return
        } else {
          this.processList.forEach(item => {
            if(item.processName.trim() == e.trim()){
                this.modifyform.processNo = item.processNo
                this.modifyform.remark = item.remark
                this.modifyform.workCenter = item.workCenter
                this.modifyform.department = item.workCenter
            }
          });
          }
          if(this.modifyform.processName.indexOf('钳铆') != 0){
              // this.listQuery.processNameGz = this.listQuery.processName
              this.$set(this.modifyform, 'processNameGz', this.modifyform.processName)
          } else {
              // this.listQuery.processNameGz = ''
              this.$set(this.modifyform, 'processNameGz', '')
          }
      }
    },
    setProcessNo(e){
      if(e){
        if(this.modifyform.technologyNo.startsWith('HW') && this.modifyform.workCenter.trim() == 'EMS总装车间'){
          return
        } else {
          this.processList.forEach(item => {
            if(item.processNo.trim() == e.trim()) {
                this.modifyform.processName = item.processName
                this.modifyform.remark = item.remark
                this.modifyform.workCenter = item.workCenter
                this.modifyform.department = item.workCenter
            }
          });
        }
          if(this.modifyform.processName.indexOf('钳铆') != 0){
              // this.listQuery.processNameGz = this.listQuery.processName
              this.$set(this.modifyform, 'processNameGz', this.modifyform.processName)
          } else {
              // this.listQuery.processNameGz = ''
              this.$set(this.modifyform, 'processNameGz', '')
          }
      }
    }
    },
    // 在生命周期函数调用"搜索"按钮绑定的函数，显示已有的数据
    mounted() {
        this.handleFilter()
    }
}
</script>

<style>
.wrong{
  color: red;
}
</style>
